package com.zzyl;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

@SpringBootTest
public class redistest {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Test
    public void test() {
        System.out.println(redisTemplate);
    }


    @Test
    public void testString(){
        redisTemplate.opsForValue().set("name", "张三");
        System.out.println(redisTemplate.opsForValue().get("name"));

        redisTemplate.opsForValue().set("token", "123qweasd",20,  TimeUnit.SECONDS);
        System.out.println(redisTemplate.opsForValue().get("token"));

        System.out.println(redisTemplate.opsForValue().setIfAbsent("lock","09876",5, TimeUnit.SECONDS));
        System.out.println(redisTemplate.opsForValue().setIfAbsent("lock","345677",5, TimeUnit.SECONDS));

    }


}
